<?php
/**
 * +----------------------------------------------------------------------
 * | summer framework
 * +----------------------------------------------------------------------
 * | Copyright (c) 2020 https://github.com/suframe/think-admin All rights reserved.
 * +----------------------------------------------------------------------
 * | Author: summer <806115620@qq.com>  2020/3/30 14:30
 * +----------------------------------------------------------------------
 */
declare (strict_types = 1);

namespace app\mall\model\traits;

use app\mall\model\MallGoodsStock;
use think\Model;
use think\model\relation\HasMany;
use think\model\relation\HasOne;

/**
 * 获取公共商品库存
 * trait GoodsStockTrait
 * @package app\mall\model\traits
 * @mixin Model
 * @property integer $goods_id
 */
trait GoodsStockTrait
{

    /**
     * 获取公共商品库存列表
     * @return HasMany
     */
    public function goodsStocks(): HasMany
    {
        return $this->hasMany(MallGoodsStock::class, 'id', 'goods_id');
    }

    /**
     * 获取公共商品库存
     * @return HasOne
     */
    public function goodsStock(): HasOne
    {
        return $this->hasOne(MallGoodsStock::class, 'id', 'goods_stock_id');
    }

    public function goodsStockBind()
    {
        return $this->goodsStock()->bind(['price', 'price_origin', 'product_no', 'stock', 'spec']);
    }

}